package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.Menu;

import java.util.List;

/**
 * Created by apple on 16/3/2.
 */
public class MainMenuAdapter extends RecyclerView.Adapter<MenuVH>{
    private Context mContext;
    private List<Menu> menus;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;

    public MainMenuAdapter(Context context,List<Menu> menus)
    {
        this.mContext=context;
        this.menus=menus;
        mInflater=LayoutInflater.from(mContext);
    }


    @Override
    public MenuVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.menu_list_item_layout,null);
        return new MenuVH(itemView);
    }

    @Override
    public void onBindViewHolder(MenuVH holder, int position) {
        Menu menu=menus.get(position);
        holder.menuNameView.setText(menu.getMenuName());
        if (null!=onClickListener)
        {
            holder.itemView.setTag(R.id.recyclerview_item_position,position);
            holder.itemView.setOnClickListener( onClickListener);
        }

    }

    @Override
    public int getItemCount() {
        if (menus==null)
        {
            return 0;
        }else
        {
            return menus.size();
        }

    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
